/**
 * @file objloader.h
 * @brief ObjLoader class definition
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk) sir.vestnik@gmail.com
 * @date 6 Jul 2010
 */
#ifndef MJN_OBJLOADER_H
#define MJN_OBJLOADER_H

#include <GL/gl.h>

#include <QtCore/QtGlobal>
#include <QtCore/QString>
#include <QtCore/QCoreApplication>

struct ObjLoaderPrivate;

namespace mjn {

/**
 * @brief Loads *.obj file and allows to create OpenGL list to render it.
 */
class ObjLoader
{
    Q_DECLARE_TR_FUNCTIONS(QbjLoader)
    public:
        ObjLoader();
        explicit ObjLoader(const QString &path);
        virtual ~ObjLoader();

        bool load(const QString &path);

        bool isValid() const {return mValid;}
        const QString &errorString() const;
        int errorLine() const;

        GLuint buildList();
        GLuint list() const {return mList;}
        void deleteList();

        /**
         * @returns true if there is valid list wrapped by this function.
         */
        inline bool listAvailable()
        {
            if (!mList) return false;
            if (!glIsList(mList)) return false;
                return true;
        }
    private:
        Q_DISABLE_COPY(ObjLoader)
        bool mValid;

        GLuint mList;

        ObjLoaderPrivate *const d;
};

}

#endif // MJN_OBJLOADER_H
